<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>收藏</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        html,
        body {
            font-size: 14px;
            height: 100%;
            background-color: #f2f2f2;
        }

        header {
            position: fixed;
            top: 0;
            width: 100%;
            height: 75px;
            text-align: left;
            background-color: #fff;
            border-bottom: 1px solid #f2f2f2;
        }

        header .back {
            position: relative;
            margin-top: 38px;
            width: 100%;
            height: 1.5rem;
            text-align: center;
        }

        .back img {
            position: absolute;
            left: 1rem;
            width: 1.5rem;
            height: 1.5rem;
            vertical-align: middle;
        }

        main {
            padding-top: 75px;
        }

        .infolist-content li {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.5rem 1rem;
            background-color: #fff;
            border-bottom: 2px solid #f2f2f2;
        }

        .infolist-content-left {
            width: 70%;
        }

        .infolist-content-right {
            width: 20%;
            text-align: center;
            line-height: 1;
            color: #FEA82F;
        }

        .jobname {
            font-weight: bolder;
            font-size: 1.1rem;
            padding: 0.5rem 0;
        }

        .salary {
            color: #FEA82F;
            margin-bottom: 0.5rem;
        }

        .jobaddress span {
            padding: 0.1rem 0.2rem;
            box-sizing: border-box;
            background-color: #F2F2F2;
            border-radius: 0.2rem;
        }

        main .none {
            display: none;
            width: 10rem;
            height: 10rem;
            color: #666;
            text-align: center;
            margin: 10rem auto;
        }

        main .none img {
            width: 100%;
        }
    </style>
</head>

<body>
    <header>
        <div class="back">
            <img src="../image/icon/back.png" alt="" onclick="api.closeWin()">
            <span>我的收藏</span>
        </div>
    </header>
    <main>
        <ul class="infolist-content">

        </ul>
        <div class="none">
            <img src="../image/icon/none2.png" alt="">
            <span>~没有收藏哟~</span>
        </div>
    </main>
</body>
<script type="text/template" id='collectJob'>
    {{~it.items:value:index}}
    <li data-id="{{=value.id}}">
        <div class="infolist-content-left">
            <div class="jobname">
                <span>{{=value.jobname}}</span>
            </div>
            <div class="salary">{{=value.salary}}</div>
            <div class="jobaddress" style="color:#989898">
                <span>{{=value.address}}</span>
                <span>{{=value.cyclelength}}</span>
            </div>
        </div>
        <div class="infolist-content-right">已收藏</div>
    </li>
    {{~}}
</script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.min.js"></script>
<script src="../script/doT.min.js" charset="utf-8"></script>
<script type="text/javascript">
    apiready = function() {
        if (!$api.getStorage('userid')) {
            $('.none').show();
        } else {
            getCollectJob();
        }
    };

    function getCollectJob() {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            modal: false
        });
        api.ajax({
            url: 'http://122.112.138.133/wangt/jianzhi/queryCollectJob.com',
            method: 'post',
            data: {
                body: {
                    data: {
                        userid: $api.getStorage('userid')
                    }
                }
            }
        }, function(ret, err) {
            if (ret) {
                if (ret.data.total != 0) {
                    $('.infolist-content').append(parttime_render('collectJob', ret.data.records));
                    api.hideProgress();
                    $('li').click(function() {
                        api.openWin({
                            name: 'jobdetails',
                            url: './jobdetails.html',
                            pageParam: {
                                id: $(this).attr('data-id')
                            }
                        })
                    })
                } else {
                    api.showProgress({
                        style: 'default',
                        animationType: 'fade',
                        title: '努力加载中...',
                        modal: false
                    });
                    setTimeout(function() {
                        api.hideProgress();
                        $('.none').show();
                    }, 2000)
                }
            }
        });
    }

    function parttime_render(id, elements, options) {
        var options = options || {};
        var elementObj = doT.template($api.byId(id).innerHTML);
        var elementData = $.extend({
            items: elements
        }, options);
        return elementObj(elementData);
    }
</script>

</html>
